import 'package:boss/models/store_area.dart';
import 'package:boss/provider/table_provider.dart';
import 'package:boss/ui/page/tableManagement/page/areaManagement/page/areaDetail/area_detail_page.dart';
import 'package:boss/ui/page/tableManagement/page/areaManagement/widget/area_management_item.dart';
import 'package:boss/ui/widget/loader/empty_widget.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class AreaManagementList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Consumer<TableProvider>(
        builder: (context, tableProvider, _) {
          if (tableProvider.storeAreas.length == 0) {
            return EmptyWidget();
          }
          return ListView.builder(
            padding: EdgeInsets.symmetric(
              horizontal: 30.w,
            ),
            itemBuilder: (context, index) {
              var current = tableProvider.storeAreas[index];

              return AreaManagementItem(
                data: current,
                onTap: () {
                  Navigator.pushNamed(context, AreaDetailPage.pageName, arguments: {
                    'storeArea': StoreArea.fromJson(current.toJson()),
                  });
                },
              );
            },
            itemCount: tableProvider.storeAreas.length,
          );
        },
      ),
    );
  }
}
